package rabbit.flt.plugins.reactor.http.matcher;

import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import rabbit.flt.plugins.common.matcher.SupportMatcher;

import java.util.function.BiFunction;

import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

public class HttpClientFinalizerMatcher implements SupportMatcher {

    @Override
    public ElementMatcher.Junction<TypeDescription> classMatcher() {
        return named("reactor.netty.http.client.HttpClientFinalizer");
    }

    @Override
    public ElementMatcher.Junction methodMatcher(TypeDescription typeDescription) {

        // responseConnection
        return named("responseSingle").and(takesArgument(0, BiFunction.class))
                .or(named("response").and(takesArgument(0, BiFunction.class)))
                .or(named("responseConnection").and(takesArgument(0, BiFunction.class)));
    }

    @Override
    public String getPluginClassName() {
        return "rabbit.flt.plugins.reactor.http.plugin.HttpClientFinalizerPlugin";
    }
}
